<!-- 添加小结 -->
<template>
  <div class="summary_modal">
    <dt-modal-edit
      ref="edit"
      :title="title"
      :label-width="130"
      okText="保存"
      cancelText="取消"
      :width="60"
      @ok="onOk"
      class="dt_modal_edit">
      <Row class="label_warp" v-show="tipsFlag">
        <Col span="24" class="tips">
          <Icon type="md-alert" class="tips_icon" />
          提示：您已输入的文字已大于300字，请控制字数以避免影响阅读体验
        </Col>
      </Row>
      <Row slot="bottom" class="label_warp" v-show="info.imageUrls && info.imageUrls.length == 9">
        <Col span="24" class="tips">
          <Icon type="md-alert" class="tips_icon" />
          日报中至多可添加9张图片
        </Col>
      </Row>
    </dt-modal-edit>
  </div>
</template>

<script>
  import editSummary from '../../opt/editSummary.js'
  import dailyApi from '@/biz/buildingHome/daily'
  export default {
    components: {},
    data() {
      return {
        tipsFlag: false,
        info: {},
        title: '添加今日小结',
        currentDate: ''
      }
    },
    methods: {
      updateTask() {
        let params = {
          taskId: 35,
          buildingId: this.$dt.buildInfo().housesId,
          date: this.currentDate,
          taskStatus: 2
        }
        dailyApi.updateTask(params).then((res) => {
          console.log('完成')
        })
      },
      show(data) {
        console.log(data, '添加小结')
        this.info = {
          content: '',
          imageUrls: [],
          currentDate: '',
          ...data
        }
        this.currentDate = data.currentDate ? data.currentDate : data.createDate.substring(0, 10)
        this.title = data.title
        this.$refs.edit.show(editSummary.options(this), this.info)
      },
      hide() {
        this.$refs.edit.hide()
        this.info = {}
      },
      summaryChange() {
        console.log(this.info.content.length)
        if (this.info.content.length + 1 > 300) {
          this.tipsFlag = true
        } else {
          this.tipsFlag = false
        }
      },
      onOk(data) {
        console.log(data, 'data')
        let imageUrls = []
        data.imageUrls.forEach((item) => {
          imageUrls.push(item.url)
        })
        let params = {
          imageUrls: imageUrls.join(','),
          date: this.$parent.currentDate,
          content: data.content,
          buildingId: this.$dt.buildInfo().housesId
        }
        if (data.id) {
          params.id = data.id
          dailyApi.updateDailySection(params).then((res) => {
            this.$Message.success('编辑成功')
            this.updateTask()
            this.$emit('success')
            this.hide()
          })
        } else {
          dailyApi.saveDailySection(params).then((res) => {
            this.$Message.success('新增成功')
            this.updateTask()
            this.$emit('success')
            this.hide()
          })
        }
      }
    },
    mounted() {}
  }
</script>
<style lang="scss" scoped>
  .summary_modal {
    .label_warp {
      text-align: center;
      margin-bottom: 15px;
      background-color: rgba(254, 252, 236, 1);
      width: auto;
      line-height: 32px;
      padding: 0 10px;

      .tips {
        line-height: 32px;
        font-size: 14px;

        .tips_icon {
          font-size: 20px;
          color: #0f42a7;
          vertical-align: sub;
        }
      }
    }
  }
</style>
